package tchk.xyz.lingyuntutorminiprogram.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import tchk.xyz.lingyuntutorminiprogram.entity.SystemConfig;
import tchk.xyz.lingyuntutorminiprogram.service.ISystemConfigService;
import tchk.xyz.lingyuntutorminiprogram.utils.Result;

import java.util.List;

@RestController
@RequestMapping("/api/admin/config")
@PreAuthorize("hasAuthority('admin:config:manage')")
public class SystemConfigController {

    @Autowired
    private ISystemConfigService systemConfigService;

    /**
     * 获取所有系统配置项
     */
    @GetMapping("/list")
    public Result<List<SystemConfig>> getConfigList() {
        return Result.success(systemConfigService.list());
    }

    /**
     * 批量更新系统配置
     * @param configList 前端传来的配置项列表
     */
    @PutMapping("/update")
    public Result<Void> updateConfigs(@RequestBody List<SystemConfig> configList) {
        if (configList != null && !configList.isEmpty()) {
            systemConfigService.updateBatchById(configList);
        }
        return Result.success();
    }
}